package gregorytersoff_boundary;

import gregorytersoff_model.Edge;
import gregorytersoff_model.Model;

import java.awt.*;
import java.util.ArrayList;

import javax.swing.*;



public class LineCanvas extends JPanel
{
	private Model model;
	private ArrayList<Edge> edges;
	/**
	 * LineCanvas draws both the lines corresponding to each Line, and the lines corresponding to each Edge. The lines for Line are established
	 * by the number of options chosen during creation of the model, and the edges are drawn as they are added to an arraylist of valid options
	 * @param m The model used to establish the initial number of lines, their sizes, and coordinates
	 */
	public LineCanvas(Model m)
	{
		model = m;
		edges = new ArrayList<Edge>();
	}
	/**
	 * Draws the lines for both the choices and edges based on the initial state of the model, and a maintained list of selected edges
	 */
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		int lines = model.getNumoptions();

		int i = 0;
		while(i < lines)
		{
			g.drawLine(model.getSpacing() * (17 - (2 * model.getNumoptions() - 1) + 4*i +1), 55,model.getSpacing() * (17 - (2 * model.getNumoptions() - 1) + 4*i +1), model.getHeight() - 200);
			
			i++;
		}
		for (int j = 0; j<edges.size(); j++)
		{
			g.drawLine(model.getSpacing() * (17 - (2 * model.getNumoptions() - 1) + 4*edges.get(j).getLine1() +1), 58 + 7*edges.get(j).getHeight(), model.getSpacing() * (17 - (2 * model.getNumoptions() - 1) + 4*edges.get(j).getLine2() +1), 58 + 7*edges.get(j).getHeight());
		}
	} 
	/**
	 * Adds an edge to the arraylist storing valid edges. This is done, rather than getting the array of edges from the model, to separate the
	 * boundary and model classes
	 * @param newedge an edge to be added to the arraylist
	 */
	public void addEdge (Edge newedge)
	{
		edges.add(newedge);
		this.repaint();
		
	}
}
